<template>
	<view class="font informedConsent">
		<view class="item">
			<view class="content">
				<view class="card">
					<view class="mybox">
						<view class="title">
							<span>*</span><text>标题</text>
						</view>
						<input type="text" v-model="title" placeholder="请输入标题">
					</view>
					<view class="mybox">
						<view class="title">
							<span>*</span><text>正文</text>
						</view>
						<textarea maxlength='-1' v-model="content" placeholder="请输入内容" styles='font-weight: 12;'></textarea>
					</view>
					<view class="mybox">
						<view class="title">
							<span>*</span><text>同意按钮文字</text>
						</view>
						<input type="text" v-model="agreed" placeholder="请输入内容">
					</view>
					<view class="mybox">
						<view class="title">
							<span>*</span><text>不同意按钮文字</text>
						</view>
						<input type="text" v-model="disagree" placeholder="请输入内容">
					</view>
				</view>
				<view class="card">
					<view class="mybox">
						<view class="uni-list-cell">
							<view class="uni-list-cell-db">是否隐藏不同意按钮</view>
							<switch style="transform:scale(0.7)" :checked="isDisagree" @change="hiddenDisagree" />
						</view>
					</view>
					<view class="mybox">
						<view class="uni-list-cell">
							<view class="uni-list-cell-db">最短阅读时间</view>
							<switch style="transform:scale(0.7)" :checked="shortestReadingTime" @change="openSecond" />
							<input type="numeric" v-model="seconds" placeholder="请设置秒数" style="width: 150rpx;height: 50rpx;font-size: 30rpx;" v-show="shortestReadingTime">
						</view>
						
					</view>
					<view class="mybox">
						<view class="uni-list-cell">
							<view class="uni-list-cell-db">每次打开均显示</view>
							<switch style="transform:scale(0.7)" :checked="isShowNum?isOpen:false" @change="haveShown" />
						</view>
					</view>
					<view class="mybox">
						<view class="uni-list-cell">
							<view class="uni-list-cell-db">仅显示一次</view>
							<switch style="transform:scale(0.7)" :checked="isShowNum?!isOpen:false" @change="accordingToA" />
						</view>
					</view>
				</view>
			</view>
			<button @click="sure" class="button1">确认</button>
			<button @click="Hidden" class="button2">返回</button>
		</view>
	</view>
</template>

<script>
	export default{
		name:"informedConsent",
		data() {
			return {
				formid:"", //问卷id
				// State:false, //进入知情同意书页面
				title:"", //知情同意书的标题
				content:"", //知情同意书的内容
				agreed:"", //同意按钮文字
				isOpen:false, //显示次数选择勾选框
				isShowNum:false, //显示次数选择勾选框
				ShowNum:0, //显示次数选择(0:不开启,1：均显示，2：显示一次)
				disagree:"", //不同意按钮文字
				isDisagree:false, //是否隐藏不同意按钮
				shortestReadingTime:false,//是否开启阅读时间
				seconds:"" //阅读的秒数
			}
		},
		onLoad:function(option){
			this.formid = option.formid
			// this.State = true
			let data = {
				formid:this.formid
			}
			this.$request('/QuestionnaireAgreementController/getAgreement','GET',data)
			.then(res=>{
				if(res.data.code == 200){
					let data = res.data.data
					this.agreed = data.agree
					this.content = data.content
					this.disagree = data.disagree
					this.seconds = data.seconds
					this.shortestReadingTime = data.shortestReadingTimeEasy !==0?true:false
					this.ShowNum = data.showNum
					this.title = data.title
					this.isShowNum = data.showNum !==0 ?true:false
					this.isDisagree = data.isDisagree == 1?true:false
					this.isOpen = this.isShowNum?(this.ShowNum==1?true:false):false
				}
			}).catch(err=>{
				console.log(err);
			})
		},
		methods:{
			// 隐藏
			Hidden () {
				uni.navigateBack()
			},
			// 确认
			sure(){
				if(!this.title){
					uni.showToast({
						title:"请输入标题",
						icon:"none"
					})
					return
				}
				else if(!this.content){
					uni.showToast({
						title:"请输入正文",
						icon:"none"
					})
					return
				}
				else if(!this.agreed){
					uni.showToast({
						title:"请输入同意按钮文字",
						icon:"none"
					})
					return
				}
				else if(!this.disagree){
					uni.showToast({
						title:"请输入不同意按钮文字",
						icon:"none"
					})
					return
				}
				let setting ={
					"formid":this.formid,
					"title":this.title,
					"content":this.content,
					"agree":this.agreed,
					"showNum":Number(this.ShowNum),
					"disagree":this.disagree,
					"shortestReadingTime":this.shortestReadingTime,
					"seconds":Number(this.seconds),
					"isDisagree":this.isDisagree
				}
				console.log(setting);
				this.$request('/QuestionnaireAgreementController/agreement','POST',setting)
				.then(res=>{
					uni.showToast({
						title:"设置成功",
						icon:"success"
					})
					setTimeout(()=>{
						uni.navigateBack()
					},1000)
				})
			},
			// 是否开启秒数
			openSecond(e){
				this.shortestReadingTime = e.detail.value
			},
			hiddenDisagree(e){
				this.isDisagree = e.detail.value
			},
			haveShown(e){
				if(e.detail.value){
					this.isShowNum = true
					this.isOpen = true
					this.ShowNum = 1
				}else{
					this.isShowNum = false
					this.isOpen = false
					this.ShowNum = 0
				}
			},
			accordingToA(e){
				if(e.detail.value){
					this.isShowNum = true
					this.isOpen = false
					this.ShowNum = 2
				}else{
					this.isShowNum = false
					this.isOpen = false
					this.ShowNum = 0
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	input,textarea{
		font-size: 30rpx;
	}
	textarea{
		width: 100%;
		height: 200rpx;
		border: 1px solid #e5e5e5;
		border-radius: 3px;
	}
	span{
		color: red; 
	}
	.title{
		margin-bottom: 30rpx;
	}
	.item{
		font-size: 12px;
		width: 90%;
		margin-left: 5%;
		input{
			border: 1px solid #e5e5e5;
			border-radius: 3px;
		}
		.mybox{
			margin-top: 30rpx;
			
		}
	}
	button{
		margin-top: 30rpx;
	}
	.button1{
		margin-top: 50rpx;
		color: white;
		background-color: #80b156;
	}
</style>